﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PacketPasser
{
    public static class StringExtensions
    {
        public static string After(this string text, string delimiter)
        {
            return text.Substring(text.IndexOf(delimiter) + delimiter.Length);
        }
        public static string Delimit(this IEnumerable<string> text, string delimiter)
        {
            return text.Aggregate((s1, s2) => s1 + delimiter + s2);
        }
        public static string PrependOrSelf(this string s, string mustStartWith)
        {
            if (s.StartsWith(mustStartWith))
                return s;
            return mustStartWith + s;
        }
        public static string PrependOrSelf(this string s, string shouldStartWith,string prependIfNot)
        {
            if (s.StartsWith(shouldStartWith))
                return s;
            return prependIfNot + s;
        }
        public static bool HasValue(this string s)
        {
            return !string.IsNullOrEmpty(s);
        }
        public static bool IsNullOrEmpty(this string s )
        {
            return string.IsNullOrEmpty(s);
        }
        public static string Before(this string text, string delimiter)
        {
            return text.Substring(0, text.IndexOf(delimiter));
        }
    }
}
